package com.ruoyi.alarm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.alarm.domain.AlarmType;
import com.ruoyi.alarm.service.IAlarmTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 告警类型Controller
 * 
 * @author yepanpan
 * @date 2025-03-10
 */
@RestController
@RequestMapping("/alarm/type")
public class AlarmTypeController extends BaseController
{
    @Autowired
    private IAlarmTypeService alarmTypeService;


    /**
     * 查询告警类型列表
     */
    @GetMapping("/select")
    public TableDataInfo select(AlarmType alarmType)
    {
        List<AlarmType> list = alarmTypeService.selectAlarmTypeList(alarmType);
        return getDataTable(list);
    }

    /**
     * 查询告警类型列表
     */
    @PreAuthorize("@ss.hasPermi('alarm:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(AlarmType alarmType)
    {
        startPage();
        List<AlarmType> list = alarmTypeService.selectAlarmTypeList(alarmType);
        return getDataTable(list);
    }

    /**
     * 导出告警类型列表
     */
    @PreAuthorize("@ss.hasPermi('alarm:type:export')")
    @Log(title = "告警类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlarmType alarmType)
    {
        List<AlarmType> list = alarmTypeService.selectAlarmTypeList(alarmType);
        ExcelUtil<AlarmType> util = new ExcelUtil<AlarmType>(AlarmType.class);
        util.exportExcel(response, list, "告警类型数据");
    }


    /**
     * 获取告警类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('alarm:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(alarmTypeService.selectAlarmTypeById(id));
    }

    /**
     * 新增告警类型
     */
    @PreAuthorize("@ss.hasPermi('alarm:type:add')")
    @Log(title = "告警类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody AlarmType alarmType)
    {
        return toAjax(alarmTypeService.insertAlarmType(alarmType));
    }

    /**
     * 修改告警类型
     */
    @PreAuthorize("@ss.hasPermi('alarm:type:edit')")
    @Log(title = "告警类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody AlarmType alarmType)
    {
        return toAjax(alarmTypeService.updateAlarmType(alarmType));
    }

    /**
     * 删除告警类型
     */
    @PreAuthorize("@ss.hasPermi('alarm:type:remove')")
    @Log(title = "告警类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(alarmTypeService.deleteAlarmTypeByIds(ids));
    }
}
